package com.example.tse.rbyair.util;

import android.content.Context;
import android.telephony.TelephonyManager;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * Created by tse on 16/1/13.
 */
public class AppInforUtil {

   // 单例模式
   private static AppInforUtil instance;

   public static AppInforUtil getInstance() {
      if (instance == null) {
         synchronized (AppInforUtil.class) {
            if (instance == null) {
               instance = new AppInforUtil();
               instance.activityId = UUID.randomUUID().toString();
            }
         }
      }
      return instance;
   }


   public static String market = "";
   private String activityId = "";

   public static int LastestVersion ;
   public static int MinAndroidVersion ;
   public static int AppVersionCode ;

   public static String AndroidUrl ;

   public static String getDeviceId(Context context) {
      TelephonyManager tm = (TelephonyManager) context
              .getSystemService(Context.TELEPHONY_SERVICE);
      return tm.getDeviceId();
   }

   // 手机型号
   public static String getInfo(Context context) {
      String mtype = android.os.Build.MODEL; // 手机型号
      return mtype;
   }

   public String getActivityId() {
      return activityId;
   }

   public void setActivityId(String activityId) {
      this.activityId = activityId;
   }

   public static String formatPrice3(String price) {
      if (!price.equals("")) {
         DecimalFormat df = new DecimalFormat("###.##");
         return df.format(Double.parseDouble(price));

      } else {
         return "";
      }
   }

   public static String formatPrice3(double d) {
      DecimalFormat df = new DecimalFormat("###.##");
      return df.format(d);
   }

   /**
    * 把毫秒转化成日期
    *
    * @param dateFormat
    *            (日期格式，例如：MM/ dd/yyyy HH:mm:ss)
    */
   public static String transferLongToDate(String dateFormat, Long millSec) {
      SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
      Date date = new Date(millSec);
      return sdf.format(date);
   }

   public static String loadWebView(String value) {
      String headString = "<html><head><meta charset='UTF-8'><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\" /><style>img{max-width:100%%;}</style></head><body>";
      String endString = "</body></html>";
      return headString + value + endString;
   }

}
